from rest_framework import serializers
from apps.models import UserInfo, UserToken

class User_Serializer(serializers.ModelSerializer):
    # ModelSerializer和Django中ModelForm功能相似
    # Serializer和Django中Form功能相似
    class Meta:
        model = UserInfo
        # 和"__all__"等价
        # fields = ('mid', 'title', 'picname', 'page_url', 'img_url')
        fields = "__all__"
class Token_Serializer(serializers.ModelSerializer):
    # ModelSerializer和Django中ModelForm功能相似
    # Serializer和Django中Form功能相似
    users = serializers.CharField(source='user.username')
    password = serializers.CharField(source='user.password')
    # /反向生成url

    class Meta:
        model = UserToken
        fields = ['token',"users","password","user"]
        fields = "__all__"



from django.contrib.auth.models import User, Group
from rest_framework import serializers


class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', 'email', 'groups')


class GroupSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Group
        fields = ('url', 'name')